﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    $(function () {
        gridList();
    })
    function gridList() {
        $('#dg').datagrid({
            url: '/SystemManage/User/GetGridJson',
            toolbar: '#toolbar',
            hideColumn: "F_Id",
            autoRowHeight: false,
            nowrap: true,
            singleSelect: true,
            pagination: true,
            pageSize: 20,
            method:'get',
            queryParams: {
                keyword: "",
            },
            columns: [[
                { field: 'F_Id', hidden: true },
                { field: 'F_Account', title: '账户', width: 100, align: 'center' },
                { field: 'F_RealName', title: '姓名', width: 100, align: 'center' },
                {
                    field: 'F_Gender', title: '性别', width: 80, align: 'center',
                    formatter: function (value, row, index) {
                        if (value == true) {
                            return '男';
                        } else {
                            return '女';
                        }
                    }
                },
                { field: 'F_MobilePhone', title: '手机', width: 80, align: 'center' },
                {
                    field: 'F_OrganizeId', title: '公司', width: 180, align: 'center',
                    formatter: function (value, row, index) {
                        return top.clients.organize[value] == null ? "" : top.clients.organize[value].fullname;
                    }
                 },
                {
                    field: 'F_DepartmentId', title: '部门', width: 80, align: 'center',
                    formatter: function (value, row, index) {
                        return top.clients.organize[value] == null ? "" : top.clients.organize[value].fullname;
                    }
                },
                {
                    field: 'F_DutyId', title: '岗位', width: 80, align: 'center',
                    formatter: function (value, row, index) {
                        return top.clients.duty[value] == null ? "" : top.clients.duty[value].fullname;
                    }
                },
                {
                    field: 'F_EnabledMark', title: '允许登录', width: 60, align: 'center',
                    formatter: function (value, row, index) {
                        if (value == 1) {
                            return '<span class=\"label label-success\">正常</span>';
                        } else if (value == 0) {
                            return '<span class=\"label label-default\">禁用</span>';
                        }
                    }
                },
                { field: 'F_CreatorTime', title: '登记时间', width: 130, align: 'right' },
                { field: 'T_Description', title: '备注', width: 200, align: 'right' }
            ]]
        });

        $("#btn_search").click(function () {
            var queryJson = {
                keyword: $("#txt_keyword").val()
            }
            $('#dg').datagrid('load', queryJson);
        });
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增用户",
            url: "/SystemManage/User/Form",
            width: "700px",
            height: "550px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var selected = $('#dg').datagrid('getSelected');
        if (selected != null) {
            $.modalOpen({
                id: "Form",
                title: "修改用户",
                url: "/SystemManage/User/Form?keyValue=" + selected.F_Id,
                width: "700px",
                height: "550px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
    function btn_delete() {
        var selected = $('#dg').datagrid('getSelected');
        if (selected != null) {
            $.deleteForm({
                url: "/SystemManage/User/DeleteForm",
                param: { keyValue: selected.F_Id },
                success: function () {
                    $('#dg').datagrid('reload');
                }
            })
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
    function btn_details() {
        var selected = $('#dg').datagrid('getSelected');
        if (selected != null) {
            $.modalOpen({
                id: "Details",
                title: "查看用户",
                url: "/SystemManage/User/Details?keyValue=" + selected.F_Id,
                width: "700px",
                height: "600px",
                btn: null,
            });
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
    function btn_revisepassword() {
        var selected = $('#dg').datagrid('getSelected');
        if (selected != null) {
            var keyValue = selected.F_Id;
            var Account = selected.F_Account;
            var RealName = selected.F_RealName;
            $.modalOpen({
                id: "RevisePassword",
                title: '重置密码',
                url: '/SystemManage/User/RevisePassword?keyValue=' + keyValue + "&account=" + escape(Account) + '&realName=' + escape(RealName),
                width: "450px",
                height: "260px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
    function btn_disabled() {
        var selected = $('#dg').datagrid('getSelected');
        if (selected != null) {
            var keyValue = selected.F_Id;
            $.modalConfirm("注：您确定要【禁用】该项账户吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/SystemManage/User/DisabledAccount",
                        param: { keyValue: keyValue },
                        success: function () {
                            $.currentWindow().$('#dg').datagrid('load', queryJson);;
                        }
                    })
                }
            });
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
    function btn_enabled() {
        var selected = $('#dg').datagrid('getSelected');
        if (selected != null) {
            var keyValue = selected.F_Id;
            $.modalConfirm("注：您确定要【启用】该项账户吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/SystemManage/User/EnabledAccount",
                        param: { keyValue: keyValue },
                        success: function () {
                            $.currentWindow().$('#dg').datagrid('load', queryJson);;
                        }
                    })
                }
            });
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
</script>

<div class="gridPanel" style="height:100%;">
    <div id="toolbar" style="padding:2px 5px;">
        <div class="dcui-btn-area">
            <a href="#" id="NF-add" authorize="yes" class="dcui-btn dcui-btn-green" iconCls="icon-add" plain="true" onclick="btn_add()"><i class="fa fa-plus"></i>新建用户</a>
            <a href="#" id="NF-delete" authorize="yes" class="dcui-btn dcui-btn-red" iconCls="icon-remove" plain="true" onclick="btn_delete()"><i class="fa fa-trash"></i>删除用户</a>
            <a href="#" id="NF-edit" authorize="yes" class="dcui-btn dcui-btn-blue" iconCls="icon-edit" plain="true" onclick="btn_edit()"><i class="fa fa-pencil"></i>修改用户</a>
            <a href="#" id="NF-details" authorize="yes" class="dcui-btn dcui-btn-purple" iconCls="icon-man" plain="true" onclick="btn_details()"><i class="fa fa-eye"></i>查看用户</a>
            <a href="#" id="NF-revisepassword" authorize="yes" class="dcui-btn dcui-btn-orange" iconCls="icon-save" plain="true" onclick="btn_revisepassword()"><i class="fa fa-key"></i>密码重置</a>
            <a href="#" id="NF-disabled" authorize="yes" class="dcui-btn dcui-btn-orange" iconCls="icon-save" plain="true" onclick="btn_disabled()"><i class="fa fa-stop-circle"></i>禁用</a>
            <a href="#" id="NF-enabled" authorize="yes" class="dcui-btn dcui-btn-orange" iconCls="icon-save" plain="true" onclick="btn_enabled()"><i class="fa fa-play-circle"></i>启用</a>
        </div>
        <script>$('#toolbar').authorizeButton()</script>
        <div class="dcui-search-area">
            关键字: <input class="easyui-textbox" style="width:110px" id="txt_keyword" placeholder="账户/姓名/手机">
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search" >查询</a>
        </div>
    </div>

    <table id="dg" class="easyui-datagrid" style="width:100%;min-height:600px;height:100%;">

    </table>
</div>